package com.studyinghome.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.studyinghome.dto.UserDTO;
import com.studyinghome.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Leslie
 * @create 2023-02-14 14:06
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/query")
    public String queryPage(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        IPage<UserDTO> userPage = userService.getPage(current, size);
        return JSON.toJSONString(userPage);
    }

    @GetMapping("/list")
    public String queryList() {
        List<UserDTO> users = userService.getList();
        return JSON.toJSONString(users);
    }
}
